package com.cwj.io.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.Scanner;

/**
 * @author: Chenwujie
 * @date: 2021-05-20 15:49
 */
public class Client {
    public static void main(String[] args) throws IOException {
        SocketChannel channel = SocketChannel.open(new InetSocketAddress("127.0.0.1", 6666));
        channel.configureBlocking(false);

        ByteBuffer buffer = ByteBuffer.allocate(1024);
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextLine()){
            String next = scanner.nextLine();
            buffer.put(next.getBytes());
            buffer.flip();
            channel.write(buffer);
        }
        channel.close();
    }
}
